#!/bin/bash
set -eu

TESTDIR=$(readlink -f $(dirname $0))
. $TESTDIR/framework

setupenvironment

buildpackage 'conflicting-package-distupgrade'
buildpackage 'conflicting-package-one'
buildpackage 'conflicting-package-two'
buildpackage 'missing-dependency'
buildpackage 'simple-package-new'
buildpackage 'simple-package-noarch'
buildpackage 'simple-package'
buildpackage 'simple-package-update-conflict'
buildpackage 'simple-package-update' # overwrites the previous built package

generaterepository_and_switch_sources "$TMPWORKINGDIRECTORY/usr/src/RPM/RPMS"

testsuccess aptget update

readonly -a simple_package_n_matches=(
	'simple-package-new - Test package'
	'simple-package-noarch - Test package'
)

readonly -a simple_package_matches=(
	'simple-package - Test package'
	"${simple_package_n_matches[@]}"
)

testpartsexhaust "${simple_package_matches[@]}" \
-- aptcache search 'simple-package'

testpartsexhaust "${simple_package_matches[@]}" \
-- aptcache search 'simple-package-*'

testpartsexhaust "${simple_package_matches[@]}" \
-- aptcache search 'simple-package*'

testpartsexhaust "${simple_package_n_matches[@]}" \
-- aptcache search 'simple-package-n*'

testempty aptcache search 'no-such-package'
